package com.newasia.shopping.converter;

import com.newasia.shopping.dal.entitys.returnValue.ItemDetail;
import com.newasia.shopping.dal.entitys.returnValue.ItemSkuCart;
import com.newasia.shopping.dto.ProductDetailDto;
import com.newasia.shopping.dto.cartDto.CartProductDto;

/**
 * Created by mic on 2019/7/23.
 */

public class CartItemConverter {

    /*public static CartProductDto item2Dto(ItemSkuCart item){
        CartProductDto cartProduct =new CartProductDto();
        cartProduct.setSpuId(item.getSpuId());
        cartProduct.setSkuId(item.getSkuId());
        cartProduct.setProductName(item.getSkuName());
        cartProduct.setSalePrice(item.getSkuPrice());
        cartProduct.setProductImg(item.getImageBig());
        if(item.getLimitNum()==null){
            cartProduct.setLimitNum(Long.valueOf(item.getNum()));
        }else if(item.getLimitNum()<0&&item.getNum()<0) {
            cartProduct.setLimitNum((long) 10);
        }else{
            cartProduct.setLimitNum(Long.valueOf(item.getLimitNum()));
        }
        return cartProduct;
    }*/

    public static CartProductDto item2Dto(ProductDetailDto itemDetail){
        CartProductDto cartProduct =new CartProductDto();
        cartProduct.setSpuId(itemDetail.getSpuId());
        cartProduct.setSkuId(itemDetail.getSkuId());
        cartProduct.setProductName(itemDetail.getSkuName());
        cartProduct.setSalePrice(itemDetail.getSkuPrice());
        cartProduct.setProductImg(itemDetail.getImageBig());
        if(itemDetail.getLimitNum()==null){
            cartProduct.setLimitNum(Long.valueOf(itemDetail.getNum()));
        }else if(itemDetail.getLimitNum()<0&&itemDetail.getNum()<0) {
            cartProduct.setLimitNum((long) 10);
        }else{
            cartProduct.setLimitNum(Long.valueOf(itemDetail.getLimitNum()));
        }
        return cartProduct;
    }

    public static CartProductDto item2Dto(CartProductDto cartProduct,ProductDetailDto itemDetail){
        cartProduct.setSpuId(itemDetail.getSpuId());
        cartProduct.setSkuId(itemDetail.getSkuId());
        cartProduct.setProductName(itemDetail.getSkuName());
        cartProduct.setSalePrice(itemDetail.getSkuPrice());
        cartProduct.setProductImg(itemDetail.getImageBig());
        if(itemDetail.getLimitNum()==null){
            cartProduct.setLimitNum(Long.valueOf(itemDetail.getNum()));
        }else if(itemDetail.getLimitNum()<0&&itemDetail.getNum()<0) {
            cartProduct.setLimitNum((long) 10);
        }else{
            cartProduct.setLimitNum(Long.valueOf(itemDetail.getLimitNum()));
        }
        return cartProduct;
    }
}
